<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.12.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>NeuZephyr: NeuZephyr::Nodes::Loss::MeanSquaredErrorNode Class Reference</title>
<link rel="icon" href="NZ_logo2.png" type="image/x-icon" />
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectlogo"><img alt="Logo" src="NZ_logo2.png"/></td>
  <td id="projectalign">
   <div id="projectname">NeuZephyr
   </div>
   <div id="projectbrief">Simple DL Framework</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.12.0 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() { codefold.init(0); });
/* @license-end */
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="inherits.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function(){ initResizable(false); });
/* @license-end */
</script>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><b>NeuZephyr</b></li><li class="navelem"><a class="el" href="namespace_neu_zephyr_1_1_nodes.html">Nodes</a></li><li class="navelem"><a class="el" href="namespace_neu_zephyr_1_1_nodes_1_1_loss.html">Loss</a></li><li class="navelem"><a class="el" href="class_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node.html">MeanSquaredErrorNode</a></li>  </ul>
</div>
</div><!-- top -->
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="class_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node-members.html">List of all members</a>  </div>
  <div class="headertitle"><div class="title">NeuZephyr::Nodes::Loss::MeanSquaredErrorNode Class Reference</div></div>
</div><!--header-->
<div class="contents">

<p>Represents the Mean Squared Error (MSE) loss function node in a computational graph.  
 <a href="#details">More...</a></p>
<div class="dynheader">
Inheritance diagram for NeuZephyr::Nodes::Loss::MeanSquaredErrorNode:</div>
<div class="dyncontent">
<div class="center"><img src="class_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node__inherit__graph.png" border="0" usemap="#a_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node_inherit__map" alt="Inheritance graph"/></div>
<map name="a_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node_inherit__map" id="a_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node_inherit__map">
<area shape="rect" title="Represents the Mean Squared Error (MSE) loss function node in a computational graph." alt="" coords="17,171,185,213"/>
<area shape="rect" href="class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node.html" title="Base class for loss function nodes in a computational graph." alt="" coords="5,80,197,123"/>
<area shape="poly" title=" " alt="" coords="104,138,104,170,98,170,98,138"/>
<area shape="rect" href="class_neu_zephyr_1_1_nodes_1_1_node.html" title="Base class for nodes in a neural network or computational graph." alt="" coords="16,5,186,32"/>
<area shape="poly" title=" " alt="" coords="104,48,104,80,98,80,98,48"/>
</map>
<center><span class="legend">[<a href="graph_legend.html">legend</a>]</span></center></div>
<div class="dynheader">
Collaboration diagram for NeuZephyr::Nodes::Loss::MeanSquaredErrorNode:</div>
<div class="dyncontent">
<div class="center"><img src="class_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node__coll__graph.png" border="0" usemap="#a_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node_coll__map" alt="Collaboration graph"/></div>
<map name="a_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node_coll__map" id="a_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node_coll__map">
<area shape="rect" title="Represents the Mean Squared Error (MSE) loss function node in a computational graph." alt="" coords="17,171,185,213"/>
<area shape="rect" href="class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node.html" title="Base class for loss function nodes in a computational graph." alt="" coords="5,80,197,123"/>
<area shape="poly" title=" " alt="" coords="104,138,104,170,98,170,98,138"/>
<area shape="rect" href="class_neu_zephyr_1_1_nodes_1_1_node.html" title="Base class for nodes in a neural network or computational graph." alt="" coords="16,5,186,32"/>
<area shape="poly" title=" " alt="" coords="104,48,104,80,98,80,98,48"/>
</map>
<center><span class="legend">[<a href="graph_legend.html">legend</a>]</span></center></div>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-methods" name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:aed665cfc7944aa7fa0ea1aa9e8d1cc61" id="r_aed665cfc7944aa7fa0ea1aa9e8d1cc61"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#aed665cfc7944aa7fa0ea1aa9e8d1cc61">MeanSquaredErrorNode</a> (<a class="el" href="class_neu_zephyr_1_1_nodes_1_1_node.html">Node</a> *input1, <a class="el" href="class_neu_zephyr_1_1_nodes_1_1_node.html">Node</a> *input2)</td></tr>
<tr class="memdesc:aed665cfc7944aa7fa0ea1aa9e8d1cc61"><td class="mdescLeft">&#160;</td><td class="mdescRight">Constructor to initialize a <code><a class="el" href="class_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node.html" title="Represents the Mean Squared Error (MSE) loss function node in a computational graph.">MeanSquaredErrorNode</a></code> for computing the Mean Squared Error (MSE) loss.  <br /></td></tr>
<tr class="separator:aed665cfc7944aa7fa0ea1aa9e8d1cc61"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a7968304569a5213ec4367c7b7da3eedb" id="r_a7968304569a5213ec4367c7b7da3eedb"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a7968304569a5213ec4367c7b7da3eedb">forward</a> () override</td></tr>
<tr class="memdesc:a7968304569a5213ec4367c7b7da3eedb"><td class="mdescLeft">&#160;</td><td class="mdescRight">Computes the forward pass of the Mean Squared Error (MSE) loss function.  <br /></td></tr>
<tr class="separator:a7968304569a5213ec4367c7b7da3eedb"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a61b5abf487d65e294354a1062755d2ae" id="r_a61b5abf487d65e294354a1062755d2ae"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a61b5abf487d65e294354a1062755d2ae">backward</a> () override</td></tr>
<tr class="memdesc:a61b5abf487d65e294354a1062755d2ae"><td class="mdescLeft">&#160;</td><td class="mdescRight">Computes the backward pass of the Mean Squared Error (MSE) loss function.  <br /></td></tr>
<tr class="separator:a61b5abf487d65e294354a1062755d2ae"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="inherit_header pub_methods_class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node"><td colspan="2" onclick="javascript:dynsection.toggleInherit('pub_methods_class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node')"><img src="closed.png" alt="-"/>&#160;Public Member Functions inherited from <a class="el" href="class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node.html">NeuZephyr::Nodes::Standard::OutputNode</a></td></tr>
<tr class="memitem:a25cd49675b51fcc993611dd9aec03b4d inherit pub_methods_class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node" id="r_a25cd49675b51fcc993611dd9aec03b4d"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node.html#a25cd49675b51fcc993611dd9aec03b4d">OutputNode</a> (<a class="el" href="class_neu_zephyr_1_1_nodes_1_1_node.html">Node</a> *input)</td></tr>
<tr class="memdesc:a25cd49675b51fcc993611dd9aec03b4d inherit pub_methods_class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node"><td class="mdescLeft">&#160;</td><td class="mdescRight">Constructor to initialize an <code><a class="el" href="class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node.html" title="Base class for loss function nodes in a computational graph.">OutputNode</a></code> with a given input node.  <br /></td></tr>
<tr class="separator:a25cd49675b51fcc993611dd9aec03b4d inherit pub_methods_class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a953ccc48d72a5e23501a6bc265415bad inherit pub_methods_class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node" id="r_a953ccc48d72a5e23501a6bc265415bad"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node.html#a953ccc48d72a5e23501a6bc265415bad">forward</a> () override</td></tr>
<tr class="memdesc:a953ccc48d72a5e23501a6bc265415bad inherit pub_methods_class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node"><td class="mdescLeft">&#160;</td><td class="mdescRight">Forward pass for the <code><a class="el" href="class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node.html" title="Base class for loss function nodes in a computational graph.">OutputNode</a></code>.  <br /></td></tr>
<tr class="separator:a953ccc48d72a5e23501a6bc265415bad inherit pub_methods_class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a2a9f8963286cd2e59fedc2c3e731835a inherit pub_methods_class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node" id="r_a2a9f8963286cd2e59fedc2c3e731835a"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node.html#a2a9f8963286cd2e59fedc2c3e731835a">backward</a> () override</td></tr>
<tr class="memdesc:a2a9f8963286cd2e59fedc2c3e731835a inherit pub_methods_class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node"><td class="mdescLeft">&#160;</td><td class="mdescRight">Backward pass for the <code><a class="el" href="class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node.html" title="Base class for loss function nodes in a computational graph.">OutputNode</a></code>.  <br /></td></tr>
<tr class="separator:a2a9f8963286cd2e59fedc2c3e731835a inherit pub_methods_class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ab6ef4ccdda9297210927b2055b5fddfc inherit pub_methods_class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node" id="r_ab6ef4ccdda9297210927b2055b5fddfc"><td class="memItemLeft" align="right" valign="top">Tensor::value_type&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node.html#ab6ef4ccdda9297210927b2055b5fddfc">getLoss</a> () const</td></tr>
<tr class="memdesc:ab6ef4ccdda9297210927b2055b5fddfc inherit pub_methods_class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node"><td class="mdescLeft">&#160;</td><td class="mdescRight">Retrieves the loss value stored in the <code><a class="el" href="class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node.html" title="Base class for loss function nodes in a computational graph.">OutputNode</a></code>.  <br /></td></tr>
<tr class="separator:ab6ef4ccdda9297210927b2055b5fddfc inherit pub_methods_class_neu_zephyr_1_1_nodes_1_1_standard_1_1_output_node"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="inherit_header pub_methods_class_neu_zephyr_1_1_nodes_1_1_node"><td colspan="2" onclick="javascript:dynsection.toggleInherit('pub_methods_class_neu_zephyr_1_1_nodes_1_1_node')"><img src="closed.png" alt="-"/>&#160;Public Member Functions inherited from <a class="el" href="class_neu_zephyr_1_1_nodes_1_1_node.html">NeuZephyr::Nodes::Node</a></td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Represents the Mean Squared Error (MSE) loss function node in a computational graph. </p>
<p>The <code><a class="el" href="class_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node.html" title="Represents the Mean Squared Error (MSE) loss function node in a computational graph.">MeanSquaredErrorNode</a></code> class computes the Mean Squared Error loss between two input tensors. The loss is calculated as the average of the squared differences between the corresponding elements of the two tensors: </p><div class="fragment"><div class="line">MSE(x, y) = 1/n * Σ (x_i - y_i)^2</div>
</div><!-- fragment --><p> where <code>x</code> and <code>y</code> are the two input tensors, and <code>n</code> is the number of elements in the tensors. This class is typically used for training models, especially in regression tasks.</p>
<p>Key features:</p><ul>
<li><b>Forward Pass</b>: Calculates the Mean Squared Error loss between the two input tensors, storing the result in the output tensor. The MSE loss is computed on a per-element basis and aggregated across the entire tensor.</li>
<li><b>Backward Pass</b>: Computes the gradients of the MSE loss with respect to the input tensors for use in backpropagation. The gradients are propagated only if the output tensor requires gradients.</li>
<li><b>Shape Compatibility</b>: Ensures that both input tensors have the same shape. An exception is thrown if the shapes do not match.</li>
<li><b>Efficient <a class="el" href="namespace_neu_zephyr_1_1_nodes_1_1_computation.html" title="Contains classes and functionality for computation nodes in a neural network or computational graph.">Computation</a></b>: The forward and backward passes are optimized for parallel execution using CUDA.</li>
</ul>
<p>This class is part of the <code><a class="el" href="namespace_neu_zephyr_1_1_nodes.html" title="Contains classes and functionality for nodes in a neural network or computational graph.">NeuZephyr::Nodes</a></code> namespace and is useful in models where Mean Squared Error is the loss function.</p>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>The <code><a class="el" href="class_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node.html" title="Represents the Mean Squared Error (MSE) loss function node in a computational graph.">MeanSquaredErrorNode</a></code> requires two input nodes, both of which must have tensors of the same shape.</li>
<li>The forward pass performs the MSE calculation on the GPU, while the backward pass computes the gradient of the MSE loss.</li>
<li>The loss is stored in the <code>loss</code> attribute, which is updated during the forward pass.</li>
<li>The gradients are stored in the <code>grad</code> attribute of the input tensors during the backward pass.</li>
</ul>
</dd></dl>
<h3><a class="anchor" id="autotoc_md55"></a>
Usage Example:</h3>
<div class="fragment"><div class="line"><span class="comment">// Example: Using MeanSquaredErrorNode in a computational graph</span></div>
<div class="line">InputNode input1({3, 3}, <span class="keyword">true</span>);  <span class="comment">// Create the first input node with shape {3, 3}</span></div>
<div class="line">InputNode input2({3, 3}, <span class="keyword">true</span>);  <span class="comment">// Create the second input node with shape {3, 3}</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">float</span> data1[] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f};  <span class="comment">// Sample input1 values</span></div>
<div class="line"><span class="keywordtype">float</span> data2[] = {1.5f, 2.5f, 3.5f, 4.5f, 5.5f, 6.5f, 7.5f, 8.5f, 9.5f};  <span class="comment">// Sample input2 values</span></div>
<div class="line">input1.output-&gt;copyData(data1);  <span class="comment">// Copy data to the first input tensor</span></div>
<div class="line">input2.output-&gt;copyData(data2);  <span class="comment">// Copy data to the second input tensor</span></div>
<div class="line"> </div>
<div class="line"><a class="code hl_function" href="#aed665cfc7944aa7fa0ea1aa9e8d1cc61">MeanSquaredErrorNode</a> mse_node(&amp;input1, &amp;input2);  <span class="comment">// Create the Mean Squared Error node</span></div>
<div class="line">mse_node.forward();  <span class="comment">// Perform the forward pass and compute the MSE loss</span></div>
<div class="line">mse_node.backward();  <span class="comment">// Perform the backward pass and compute gradients</span></div>
<div class="line"> </div>
<div class="line">std::cout &lt;&lt; <span class="stringliteral">&quot;MSE Loss: &quot;</span> &lt;&lt; mse_node.getLoss() &lt;&lt; std::endl;  <span class="comment">// Print the computed MSE loss</span></div>
<div class="ttc" id="aclass_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node_html_aed665cfc7944aa7fa0ea1aa9e8d1cc61"><div class="ttname"><a href="#aed665cfc7944aa7fa0ea1aa9e8d1cc61">NeuZephyr::Nodes::Loss::MeanSquaredErrorNode::MeanSquaredErrorNode</a></div><div class="ttdeci">MeanSquaredErrorNode(Node *input1, Node *input2)</div><div class="ttdoc">Constructor to initialize a MeanSquaredErrorNode for computing the Mean Squared Error (MSE) loss.</div><div class="ttdef"><b>Definition</b> <a href="_nodes_8cu_source.html#l00489">Nodes.cu:489</a></div></div>
</div><!-- fragment --><dl class="section see"><dt>See also</dt><dd><a class="el" href="#a7968304569a5213ec4367c7b7da3eedb" title="Computes the forward pass of the Mean Squared Error (MSE) loss function.">forward()</a> for the Mean Squared Error computation in the <a class="el" href="#a7968304569a5213ec4367c7b7da3eedb" title="Computes the forward pass of the Mean Squared Error (MSE) loss function.">forward</a> pass. </dd>
<dd>
<a class="el" href="#a61b5abf487d65e294354a1062755d2ae" title="Computes the backward pass of the Mean Squared Error (MSE) loss function.">backward()</a> for gradient computation in the <a class="el" href="#a61b5abf487d65e294354a1062755d2ae" title="Computes the backward pass of the Mean Squared Error (MSE) loss function.">backward</a> pass.</dd></dl>
<dl class="section author"><dt>Author</dt><dd>Mgepahmge (<a href="https://github.com/Mgepahmge">https://github.com/Mgepahmge</a>)</dd></dl>
<dl class="section date"><dt>Date</dt><dd>2024/12/07 </dd></dl>

<p class="definition">Definition at line <a class="el" href="_nodes_8cuh_source.html#l03088">3088</a> of file <a class="el" href="_nodes_8cuh_source.html">Nodes.cuh</a>.</p>
</div><h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a id="aed665cfc7944aa7fa0ea1aa9e8d1cc61" name="aed665cfc7944aa7fa0ea1aa9e8d1cc61"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aed665cfc7944aa7fa0ea1aa9e8d1cc61">&#9670;&#160;</a></span>MeanSquaredErrorNode()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">NeuZephyr::Nodes::Loss::MeanSquaredErrorNode::MeanSquaredErrorNode </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="class_neu_zephyr_1_1_nodes_1_1_node.html">Node</a> *</td>          <td class="paramname"><span class="paramname"><em>input1</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="class_neu_zephyr_1_1_nodes_1_1_node.html">Node</a> *</td>          <td class="paramname"><span class="paramname"><em>input2</em></span>&#160;)</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">explicit</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Constructor to initialize a <code><a class="el" href="class_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node.html" title="Represents the Mean Squared Error (MSE) loss function node in a computational graph.">MeanSquaredErrorNode</a></code> for computing the Mean Squared Error (MSE) loss. </p>
<p>The constructor initializes a <code><a class="el" href="class_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node.html" title="Represents the Mean Squared Error (MSE) loss function node in a computational graph.">MeanSquaredErrorNode</a></code>, which computes the MSE loss between two input nodes. It checks that both input nodes have the same shape and sets up the necessary internal structures for the loss calculation.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">input1</td><td>A pointer to the first input node. The <code>output</code> tensor of this node will be used as the predicted values. </td></tr>
    <tr><td class="paramname">input2</td><td>A pointer to the second input node. The <code>output</code> tensor of this node will be used as the ground truth values.</td></tr>
  </table>
  </dd>
</dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">std::invalid_argument</td><td>if <code>input1</code> and <code>input2</code> do not have the same shape.</td></tr>
  </table>
  </dd>
</dl>
<ul>
<li>The constructor verifies that the shapes of the two input tensors are the same. If they are not, an exception is thrown.</li>
<li>The second input node (<code>input2</code>) is added to the <code>inputs</code> vector, while the first input node is inherited from the <code>OutputNode</code> base class.</li>
<li>The <code>type</code> attribute is set to <code>"MeanSquaredError"</code>, indicating the type of operation this node represents.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>The MSE loss is only calculated if the input nodes have matching shapes. If the shapes do not match, an exception will be thrown to ensure consistency.</li>
<li>The constructor initializes the internal state and prepares the node for the forward and backward passes.</li>
</ul>
</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="#a7968304569a5213ec4367c7b7da3eedb" title="Computes the forward pass of the Mean Squared Error (MSE) loss function.">forward()</a> for computing the MSE loss in the <a class="el" href="#a7968304569a5213ec4367c7b7da3eedb" title="Computes the forward pass of the Mean Squared Error (MSE) loss function.">forward</a> pass. </dd>
<dd>
<a class="el" href="#a61b5abf487d65e294354a1062755d2ae" title="Computes the backward pass of the Mean Squared Error (MSE) loss function.">backward()</a> for computing the gradients in the <a class="el" href="#a61b5abf487d65e294354a1062755d2ae" title="Computes the backward pass of the Mean Squared Error (MSE) loss function.">backward</a> pass.</dd></dl>
<dl class="section author"><dt>Author</dt><dd>Mgepahmge (<a href="https://github.com/Mgepahmge">https://github.com/Mgepahmge</a>)</dd></dl>
<dl class="section date"><dt>Date</dt><dd>2024/12/07 </dd></dl>

<p class="definition">Definition at line <a class="el" href="_nodes_8cu_source.html#l00489">489</a> of file <a class="el" href="_nodes_8cu_source.html">Nodes.cu</a>.</p>

</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a id="a61b5abf487d65e294354a1062755d2ae" name="a61b5abf487d65e294354a1062755d2ae"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a61b5abf487d65e294354a1062755d2ae">&#9670;&#160;</a></span>backward()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void NeuZephyr::Nodes::Loss::MeanSquaredErrorNode::backward </td>
          <td>(</td>
          <td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">override</span><span class="mlabel">virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Computes the backward pass of the Mean Squared Error (MSE) loss function. </p>
<p>This method computes the gradients of the MSE loss with respect to the input tensors (<code>inputs[0]</code> and <code>inputs[1]</code>). The gradients are calculated only if the output tensor requires gradients, and they are used for backpropagation in training deep learning models.</p>
<p>The backward pass is performed using a CUDA kernel to efficiently compute the gradients in parallel on the GPU.</p>
<ul>
<li>The method first checks if the output tensor requires gradients by calling <code>requiresGrad()</code> on the output.</li>
<li>If gradients are required, a CUDA kernel (<code>MSEBackward</code>) is launched to compute the gradients of the loss with respect to both input tensors.</li>
<li>The gradients are computed by comparing the predicted values (<code>inputs[0]</code>) and the ground truth values (<code>inputs[1]</code>) in a parallel manner across all elements of the tensors.</li>
<li>The result is stored in the <code>grad</code> attribute of the output tensor.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>The method assumes that both input tensors have the same shape, as validated during the initialization phase.</li>
<li>The <code>requiresGrad()</code> check ensures that gradients are only computed if necessary, avoiding unnecessary computations.</li>
<li>This method is essential for updating the model's parameters during the training process through backpropagation.</li>
</ul>
</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="#a7968304569a5213ec4367c7b7da3eedb" title="Computes the forward pass of the Mean Squared Error (MSE) loss function.">forward()</a> for the <a class="el" href="#a7968304569a5213ec4367c7b7da3eedb" title="Computes the forward pass of the Mean Squared Error (MSE) loss function.">forward</a> pass, which computes the MSE loss.</dd></dl>
<dl class="section author"><dt>Author</dt><dd>Mgepahmge (<a href="https://github.com/Mgepahmge">https://github.com/Mgepahmge</a>)</dd></dl>
<dl class="section date"><dt>Date</dt><dd>2024/12/07 </dd></dl>

<p>Implements <a class="el" href="class_neu_zephyr_1_1_nodes_1_1_node.html#a41914155871c84330701f9d1649b39f3">NeuZephyr::Nodes::Node</a>.</p>

<p class="definition">Definition at line <a class="el" href="_nodes_8cu_source.html#l00516">516</a> of file <a class="el" href="_nodes_8cu_source.html">Nodes.cu</a>.</p>
<div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><img src="class_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node_a61b5abf487d65e294354a1062755d2ae_cgraph.png" border="0" usemap="#aclass_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node_a61b5abf487d65e294354a1062755d2ae_cgraph" alt=""/></div>
<map name="aclass_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node_a61b5abf487d65e294354a1062755d2ae_cgraph" id="aclass_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node_a61b5abf487d65e294354a1062755d2ae_cgraph">
<area shape="rect" title="Computes the backward pass of the Mean Squared Error (MSE) loss function." alt="" coords="5,5,174,64"/>
<area shape="rect" href="namespace_neu_zephyr_1_1_kernels.html#ad6f88feb98bcc258c6709f97eb249e05" title="Kernel function to compute the gradient of the Mean Squared Error (MSE) loss for backpropagation." alt="" coords="222,13,359,56"/>
<area shape="poly" title=" " alt="" coords="174,32,206,32,206,37,174,37"/>
</map>
</div>

</div>
</div>
<a id="a7968304569a5213ec4367c7b7da3eedb" name="a7968304569a5213ec4367c7b7da3eedb"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a7968304569a5213ec4367c7b7da3eedb">&#9670;&#160;</a></span>forward()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void NeuZephyr::Nodes::Loss::MeanSquaredErrorNode::forward </td>
          <td>(</td>
          <td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">override</span><span class="mlabel">virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Computes the forward pass of the Mean Squared Error (MSE) loss function. </p>
<p>This method calculates the Mean Squared Error (MSE) loss between two input tensors. The loss is computed by comparing the predicted values (<code>inputs[0]</code>) to the ground truth values (<code>inputs[1]</code>) element-wise. The result is accumulated in the <code>loss</code> attribute of the node.</p>
<p>The computation is performed in parallel on the GPU using CUDA kernels for efficiency.</p>
<ul>
<li>The method first calls the <code><a class="el" href="#a7968304569a5213ec4367c7b7da3eedb" title="Computes the forward pass of the Mean Squared Error (MSE) loss function.">forward()</a></code> method of the <code>OutputNode</code> base class to handle any initialization and setup required by the base class.</li>
<li>CUDA is used to compute the MSE loss across the entire tensor. A kernel is launched to calculate the squared differences between the elements of the two input tensors.</li>
<li>The results from the GPU computation are copied to the host memory, and the total MSE loss is accumulated.</li>
<li>The final computed loss is stored in the <code>loss</code> attribute.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>The <code>inputs</code> vector must contain exactly two nodes: the predicted values and the ground truth values. Both tensors must have the same shape, and this is validated during the initialization.</li>
<li>The loss is stored in the <code>loss</code> attribute, which is updated after each forward pass.</li>
</ul>
</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="#a61b5abf487d65e294354a1062755d2ae" title="Computes the backward pass of the Mean Squared Error (MSE) loss function.">backward()</a> for the <a class="el" href="#a61b5abf487d65e294354a1062755d2ae" title="Computes the backward pass of the Mean Squared Error (MSE) loss function.">backward</a> pass, which computes the gradients of the MSE loss.</dd></dl>
<dl class="section author"><dt>Author</dt><dd>Mgepahmge (<a href="https://github.com/Mgepahmge">https://github.com/Mgepahmge</a>)</dd></dl>
<dl class="section date"><dt>Date</dt><dd>2024/12/07 </dd></dl>

<p>Implements <a class="el" href="class_neu_zephyr_1_1_nodes_1_1_node.html#a64e42ba40199e35bfe453ef14b2d15c0">NeuZephyr::Nodes::Node</a>.</p>

<p class="definition">Definition at line <a class="el" href="_nodes_8cu_source.html#l00498">498</a> of file <a class="el" href="_nodes_8cu_source.html">Nodes.cu</a>.</p>
<div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><img src="class_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node_a7968304569a5213ec4367c7b7da3eedb_cgraph.png" border="0" usemap="#aclass_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node_a7968304569a5213ec4367c7b7da3eedb_cgraph" alt=""/></div>
<map name="aclass_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node_a7968304569a5213ec4367c7b7da3eedb_cgraph" id="aclass_neu_zephyr_1_1_nodes_1_1_loss_1_1_mean_squared_error_node_a7968304569a5213ec4367c7b7da3eedb_cgraph">
<area shape="rect" title="Computes the forward pass of the Mean Squared Error (MSE) loss function." alt="" coords="5,5,174,64"/>
<area shape="rect" href="namespace_neu_zephyr_1_1_kernels.html#ad6d39bc957466f1774a049fe41f73270" title="Kernel function to compute the Mean Squared Error (MSE) loss between predicted and real values." alt="" coords="222,13,359,56"/>
<area shape="poly" title=" " alt="" coords="174,32,206,32,206,37,174,37"/>
</map>
</div>

</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li>D:/C Program/Simple-CPP-DL-Framework/include/NeuZephyr/<a class="el" href="_nodes_8cuh_source.html">Nodes.cuh</a></li>
<li>D:/C Program/Simple-CPP-DL-Framework/src/<a class="el" href="_nodes_8cu_source.html">Nodes.cu</a></li>
</ul>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.12.0
</small></address>
</div><!-- doc-content -->
</body>
</html>
